package org.dawfinn.droiditarian.server.data;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Link;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Deed {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	@Persistent
	private String name;
	@Persistent
	private String description;
	@Persistent
	private String explanation;
	@Persistent
	private Link moreInfo;
	@Persistent
	private Date releaseDate;
	@Persistent
	private Integer favoriteCount = 0;
	@Persistent
	private Integer completedCount = 0;

	public Deed(String name, String description, String explanation, Link moreInfo, Date releaseDate) {
		this.name = name;
		this.description = description;
		this.explanation = explanation;
		this.moreInfo = moreInfo;
		this.releaseDate = releaseDate;
		this.favoriteCount = 0;
		this.completedCount = 0;
	}

	public Deed(Key key, String name, String description, String explanation, Link moreInfo, Date releaseDate) {
		this(name, description, explanation, moreInfo, releaseDate);
		this.key = key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getExplanation() {
		return explanation;
	}

	public void setExplanation(String explanation) {
		this.explanation = explanation;
	}

	public Link getMoreInfo() {
		return moreInfo;
	}

	public void setMoreInfo(Link moreInfo) {
		this.moreInfo = moreInfo;
	}

	public Date getReleaseDate() {
		return releaseDate;
	}

	public void setReleaseDate(Date releaseDate) {
		this.releaseDate = releaseDate;
	}

	public int getFavoriteCount() {
		return favoriteCount != null ? favoriteCount : 0;
	}

	public void setFavoriteCount(int favoriteCount) {
		this.favoriteCount = favoriteCount;
	}

	public int getCompletedCount() {
		return completedCount != null ? completedCount : 0;
	}

	public void setCompletedCount(int completedCount) {
		this.completedCount = completedCount;
	}

	public String getWebsafeKey() {
		return KeyFactory.keyToString(key);
	}
}
